home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / os2 / pmaud11.zip / PMAUD.C < prev    next >
C/C++ Source or Header  |  1996-04-05  |  3KB  |  115 lines

  1. /*
  2.  *   PMaud v1.1
  3.  *
  4.  * This is a presentation manager app that simply plays a .WAV, and exits.
  5.  *   No window should ever be displayed...this eliminates the annoying .WAV
  6.  *   editor that comes up everytime I click on a .WAV file from my desktop.
  7.  *   It simply plays the sound, and exits, without ever using any 'screen
  8.  *   real estate.'  Actually, this should theoretically work for any sound
  9.  *   file type that MMOS/2 supports, and more than one in each run. (That is,
  10.  *   if I specify foo.wav and bar.snd in the command line, they should both
  11.  *   play. Additionally, wildcards are expanded, and all files matching the
  12.  *   wildcard spec will be played.)
  13.  *
  14.  *  I wrote this to figure out how OS/2 Multimedia programming works at 4:00am.
  15.  *  It therefore follows logically that I take no blame for any of it.  :)
  16.  *
  17.  *  To compile (as I did) with EMX v0.9b, you'll need to have installed the
  18.  *   multimedia import libraries (can be found at
  19.  *   ftp://hobbes.nmsu.edu/os2/unix/emx09b/contrib/mm4emx10.zip)
  20.  *
  21.  *  Written by Ryan C. Gordon, 1996. Feel free to use this source code in
  22.  *   any way you see fit, just drop me a note so I know someone's getting use
  23.  *   out of it.  (mailto:warped42@ix.netcom.com)
  24.  */
  25.  
  26. #define INCL_WIN
  27. #define INCL_DOS
  28. #include <os2.h>
  29. #include <stdlib.h>
  30. #include "mciplay.h"
  31.  
  32. /* Global variables. */
  33. HWND hwndFrame, hwndClient;
  34. MCIPLAYARGS mcip;
  35.  
  36. void sndthread(void *dummy)
  37. /*
  38.  * This function calls the mciplay() function, and then ends the program with
  39.  *  a posted WM_QUIT message.
  40.  */
  41. {
  42.     mciplay(&mcip);
  43.  
  44.     WinPostMsg(hwndClient, WM_QUIT, NULL, NULL);
  45.  
  46. } /* sndthread */
  47.  
  48.  
  49. MRESULT EXPENTRY AudWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  50. /*
  51.  * Simple window procedure: in WM_CREATE, spin the work thread, and just
  52.  *   defaultly handle messages until it finishes. (Without some sort of
  53.  *   message queue-handling procedure, though, the presentation manager
  54.  *   will 'lock up' until the work thread finishes.)
  55.  */
  56. {
  57.     static TID tidSound;
  58.  
  59.     switch (msg)
  60.     {
  61.         case WM_CREATE:
  62.             if (DosCreateThread (&tidSound, (PFNTHREAD) sndthread,
  63.                                  (ULONG) NULL, 0, 32768))
  64.                 WinPostMsg(hwnd, WM_QUIT, NULL, NULL);
  65.  
  66.             return(0);
  67.  
  68.     } /* switch */
  69.  
  70.     return(WinDefWindowProc(hwnd, msg, mp1, mp2));
  71.  
  72. } /* AudWndProc */
  73.  
  74.  
  75. int main(int argc, char **argv)
  76. {
  77.     static CHAR  szClientClass [] = "PMaudClass";
  78.     static ULONG flFrameFlags = 0;
  79.     HAB hab;
  80.     HMQ hmq;
  81.     QMSG qmsg;
  82.  
  83.     _wildcard(&argc, &argv);  /* geeze...100% API calls before this... :) */
  84.  
  85.     mcip.ARGC = argc;        /* Setup for later call to mciplay()... */
  86.     mcip.ARGV = argv;
  87.  
  88.     hab = WinInitialize(0);
  89.     hmq = WinCreateMsgQueue(hab, 0);
  90.  
  91.     WinRegisterClass(hab, szClientClass, AudWndProc, 0, 0);
  92.  
  93.     hwndFrame = WinCreateStdWindow(HWND_DESKTOP,
  94.                                    0,
  95.                                    &flFrameFlags,
  96.                                    szClientClass,
  97.                                    NULL,
  98.                                    0L,
  99.                                    0,
  100.                                    0,
  101.                                    &hwndClient);
  102.  
  103.     while (WinGetMsg(hab, &qmsg, NULLHANDLE, 0, 0))
  104.         WinDispatchMsg(hab, &qmsg);
  105.  
  106.     /* Deinitialize Presentation Manager stuff... */
  107.     WinDestroyWindow(hwndFrame);
  108.     WinDestroyMsgQueue(hmq);
  109.     WinTerminate(hab);
  110.  
  111.     return(0);
  112. } /* main */
  113.  
  114. /* end of pmaud.c */
  115.